package com.alibaba.mq.consumer.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * 参考资料：https://blog.csdn.net/qq_35387940/article/details/100514134
 *
 * @Description
 * @Author louxiujun
 * @Date 2020/6/21 23:08
 **/
@Component
@RabbitListener(queues = "TestDirectQueue")//监听的队列名称 TestDirectQueue
public class DirectReceiver {

    @RabbitHandler
    public void process(@Payload Map<String, Object> payload,
//                        @Headers Map<String, Object> headers,
                        Channel channel) throws IOException {

        System.out.println("DirectReceiver消费者收到消息  : " + payload.toString());
//        Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
//        channel.basicAck(deliveryTag, false);
    }
}
